package gdconf

import (
	"server_cluster/common/logger"
)

// 地牢活动配置表

type DungeonActivityConfig struct {
	DungeonActivityId int32     `csv:"Id" gorm:"primary_key;autoIncrement:false"` // 活动id
	Type              int32     `csv:"Type,omitempty"`                            // 活动类型
	OpenTimeRange     TimeRange `csv:"DuringTime,omitempty"`                      // 开放时间范围
	PlayTimeRange     TimeRange `csv:"PlayTime,omitempty"`                        // 游玩时间范围
	NeedOpenStateId   int32     `csv:"UnlockCondition,omitempty"`                 // 所需功能开放id
}

func (a *DungeonActivityConfig) TableName() string {
	return "config_dungeon_activity"
}

func (g *GameDataConfig) saveDungeonActivityConfig() {
	saveTableToDb[DungeonActivityConfig](g.Db, readTable[DungeonActivityConfig](g.CsvPathPrefix+"Activity.csv"))
}

func (g *GameDataConfig) loadDungeonActivityConfig() {
	g.GameDataMaps.DungeonActivityConfigMap = make(map[int32]*DungeonActivityConfig)
	for _, activityConfig := range loadTableFromDb[DungeonActivityConfig](g.Db) {
		g.GameDataMaps.DungeonActivityConfigMap[activityConfig.DungeonActivityId] = activityConfig
	}
	logger.Info("DungeonActivityConfig Count: %v", len(g.GameDataMaps.DungeonActivityConfigMap))
}

func GetDungeonActivityConfig(dungeonActivityId int32) *DungeonActivityConfig {
	value, exist := CONF.GameDataMaps.DungeonActivityConfigMap[dungeonActivityId]
	if !exist {
		logger.Error("[ConfigNotFound] DungeonActivityConfig, dungeonActivityId: %v", dungeonActivityId)
		return nil
	}
	return value
}

func DungeonActivityConfigMap() map[int32]*DungeonActivityConfig {
	return CONF.GameDataMaps.DungeonActivityConfigMap
}
